<template>
  <div class="app-container">
    <el-dialog append-to-body title="选择角色" width="400px" :visible.sync="visible" @close="visible = false">
      <div style="height: 350px;overflow: hidden;">
        <compTree
          ref="tree"
          :show-search="false"
          :tree-show-checkbox="true"
          :tree-data="treeData"
          @treeNodeCheck="treeNodeCheck"
        />
      </div>
      <div slot="footer">
        <el-button type="primary" @click="dialogConfirm">确定</el-button>
        <el-button @click="visible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getRoleList } from '@/api/user'
import { ParamArr, SQLTable } from '../../../public/js/paramarr'

export default {
  data() {
    return {
      visible: false,
      treeData: [],
      node: {} // 当前选择的节点
    }
  },
  methods: {
    open(ok) {
      this.ok = ok
      getRoleList(new ParamArr()).then(vPar => {
        const nodes = []
        const nodeMap = new Map()
        const table = new SQLTable(vPar.getTable('QryRole'))
        table.first()
        while (!table.eof()) {
          const node = {}
          node['id'] = table.getValueByName('ID')
          node['pid'] = table.getValueByName('PID')
          node['text'] = table.getValueByName('Name')
          node['value'] = table.getValueByName('Value')
          node['loginForbit'] = table.getValueByName('LoginForbit')
          node['dataRole'] = table.getValueByName('DataRole')
          node['icon'] = 'yonghu'
          node['folder'] = false
          nodes.push(node)
          nodeMap.set(node.id, node)
          table.next()
        }
        this.treeData = nodes
      })
      this.visible = true
    },
    treeNodeCheck(a, b) {
      this.node = b.checkedNodes
    //   console.log(b.checkedNodes)
    },
    dialogConfirm() {
      this.ok(this.node)
      this.visible = false
    }
  }
}
</script>

<style>

</style>
